package logic

import (
	"context"
	"novel-world/model/mysql"

	"novel-world/novelrpc/internal/svc"
	"novel-world/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BooksAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBooksAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BooksAddLogic {
	return &BooksAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BooksAddLogic) BooksAdd(in *novelrpc.BooksAddRequest) (*novelrpc.BooksAddResponse, error) {
	// todo: add your logic here and delete this line
	user := &mysql.Books{
		UserId:  int(in.UserId),
		NovelId: int(in.NovelId),
	}
	if err := user.BooksAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &novelrpc.BooksAddResponse{
		BooksId: int64(user.ID),
	}, nil
}
